package adapletplugin.editors.pages;

import objects.MappingFile;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;

import adapletplugin.editors.input.MapFileEditorInput;

public class MapFileViewPage extends FormPage
{
	private MappingFile fMap;

	private ScrolledForm fForm;
	private FormToolkit fToolkit;

	private Text fDisplayText;

	public MapFileViewPage(FormEditor editor)
	{
		super(editor, "mapfile.view", "View Map File");

		fMap = ((MapFileEditorInput) editor.getEditorInput()).getMapFile();
	}

	@Override
	protected void createFormContent(IManagedForm managedForm)
	{
		fForm = managedForm.getForm();
		fForm.setText("Map File Preview");

		fToolkit = managedForm.getToolkit();

		Composite body = fForm.getBody();
		body.setLayout(new GridLayout(1, true));

		fDisplayText = fToolkit.createText(body, "", SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL);
		fDisplayText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

		fDisplayText.setText(fMap.toString());
	}

	public void refresh()
	{
		if (fDisplayText != null)
		{
			fDisplayText.setText(fMap.toString());
		}
	}

}
